from common.base_s import Base, By, get_driver
import time


class ManagePage(Base):  # 页面类(对象)继承Base基础类
    """封装表现层:制作每个元素的定位器"""

    order_manage_loc = (By.XPATH, '//*[@id="menu-ul"]/li[4]')  # 定位菜单栏 订单管理元素
    order_number_loc = (By.NAME, 'order_sn')  # 订单列表中的 订单号
    search_loc = (By.XPATH, '/html/body/div[3]/form/input[3]')  # 搜索按钮定位器
    see_loc = (By.LINK_TEXT, '查看')  # 查看按钮定位器

    first_order_number = (By.XPATH, '//*[@id="order_0"]')  # 第一个订单号

    merge_order_button = (By.XPATH, '//*[@id="sub-menu-04_merge_order"]/a')  # 合并订单
    merge_order_main = (By.XPATH, '//*[@id="to_order_sn"]')  # 合并订单主订单
    merge_order_follow = (By.XPATH, '//*[@id="from_order_sn"]')  # 合并订单从订单
    merge_order = (By.XPATH, '//*[@id="merge"]')  # 合并

    order_number2_loc =(By.XPATH, '/html/body/form/div[1]/table/tbody/tr[3]/td[2]')  # 查看后的订单编号
    order_express_loc =(By.XPATH, '/html/body/form/div[1]/table/tbody/tr[6]/td[2]')  # 查看后的快递方式
    order_money_loc =(By.XPATH, '/html/body/form/div[3]/table/tbody/tr[5]/td/div/strong')  # 查看后的金额

    """封装操作层,每一个元素的操作,都写成一个方法"""

    def get_in_menu_frame1(self):  # 进入菜单栏 iframe  订单列表
        """
        获取iframe 进入
        :return:
        """
        self.iframe_index(1)

    def order_management1(self):  # 点击订单管理项
        """
        点击订单管理项
        :return:
        """
        self.click(self.order_manage_loc)

    def get_in_order_frame1(self, index):  # 进入 右边输入框 iframe  订单列表
        """
        获取iframe 进入
        :return:
        """
        self.driver.switch_to.frame(index)

    def generate_number1(self, generate_number):  # 订单号输入 。调用生成订单的号码。
        """
        订单号 输入 订单
        :return:
        """
        self.send_keys(self.order_number_loc, generate_number)



    def search_butten1(self):  # 搜索按钮
        """
        搜索按钮
        :return:
        """
        self.click(self.search_loc)

    def see1(self):  # 查看按钮
        """
        查看
        :return:
        """
        self.click(self.see_loc)

    def number2(self):  # 查看后的订单号码
        return self.text(self.order_number2_loc)

    def express2(self):  # 查看后的快递方式
        return self.text(self.order_express_loc)

    def money2(self):  # 查看后的订单金额
        return self.text(self.order_money_loc)

    def first_order_number1(self):  # 获取第一个订单号
        return self.text(self.first_order_number)
    '''
    merge_order_button = (By.XPATH, '//*[@id="sub-menu-04_merge_order"]/a')  # 合并订单
    merge_order_main = (By.XPATH, '//*[@id="to_order_sn"]')  # 合并订单主订单
    merge_order_follow = (By.XPATH, '//*[@id="from_order_sn"]]')  # 合并订单从订单
    merge_order = (By.XPATH, '//*[@id="merge"]')  # 合并
    '''

    def click_merge_order_button(self):  # 点击合并订单
        self.click(self.merge_order_button)

    def input_merge_order_main(self, merge_order_main1):  # 输入主订单号
        self.send_keys(self.merge_order_main, merge_order_main1)

    def input_merge_order_follow(self, merge_order_follow1):  # 输入从订单号
        self.send_keys(self.merge_order_follow, merge_order_follow1)

    def click_merge_order(self):  # 点击 合并
        self.click(self.merge_order)








if __name__ == '__main__':
    login = ManagePage(get_driver())  # 打开浏览器
    login.login_act()  # 调用Base   进行登录


    login.get_in_menu_frame1()  # 进入 菜单栏iframe
    login.order_management1()  # 点击订单管理项

    login.click_merge_order_button()  # 点击合并订单
    login.quit_element_frame()  # 退出iframe
    time.sleep(2)
    login.get_in_order_frame1(2)  # 进入合并的 iframe
    time.sleep(2)

    login.input_merge_order_main(2023020238097)  # 输入主订单号
    login.input_merge_order_follow(2023020150442)  # 输入从订单号


    login.click_merge_order()  # 点击合并

    login.alert_accept()
    time.sleep(3)
    login.alert_accept()








